package com.apps.gomdiem.activity;

import java.util.ArrayList;

import com.apps.gomdiem.R;
import com.apps.gomdiem.hardcode.MyHardCode;
import com.apps.gomdiem.helper.DataBaseHelper;
import com.apps.gomdiem.model.MenuList;
import com.apps.gomdiem.model.Store;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class AddStore extends Activity{
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.add_store);
		
		Button btnAdd =(Button)findViewById(R.id.btnAddStore);
		btnAdd.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				EditText idStore =(EditText)findViewById(R.id.edtID);
				String pIDStore= idStore.getText().toString();
				EditText nameStore =(EditText)findViewById(R.id.edtName);
				String pNameStore= nameStore.getText().toString();
				EditText addressStore =(EditText)findViewById(R.id.edtAddress);
				String pAddressStore= addressStore.getText().toString();
				EditText imgStore =(EditText)findViewById(R.id.edtIMG);
				String pImgStore= imgStore.getText().toString();
				EditText pointStore =(EditText)findViewById(R.id.edtPoint);
				String pPointStore= pointStore.getText().toString();
				
				DataBaseHelper db = new DataBaseHelper(getApplicationContext());
				db.getWritableDatabase();
				Store pStore = new Store();
				pStore.idStore =pIDStore;
				pStore.nameStore=pNameStore;
				pStore.addressStore=pAddressStore;
				pStore.linkImg=pImgStore;
				pStore.point=pPointStore;
				db.addStore(pStore);
				Toast.makeText(getApplicationContext(), " Added successfully.",
						Toast.LENGTH_SHORT).show();
			}
		});
		Button btnAddAll =(Button)findViewById(R.id.btnAddAllStore);
		btnAddAll.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				ArrayList<Store> myArray=MyHardCode.getStore();
				for (int i = 0; i < myArray.size(); i++) {
					DataBaseHelper db = new DataBaseHelper(getApplicationContext());
					db.getWritableDatabase();
					Store pStore = new Store();
					pStore.idStore =myArray.get(i).idStore;
					pStore.nameStore=myArray.get(i).nameStore;
					pStore.addressStore=myArray.get(i).addressStore;
					pStore.linkImg=myArray.get(i).linkImg;
					pStore.point=myArray.get(i).point;
					db.addStore(pStore);
					
				}
				Toast.makeText(getApplicationContext(), " Added all store successfully.",
						Toast.LENGTH_SHORT).show();
				finish();
			}
		});
		
		Button btnAddMenu =(Button)findViewById(R.id.btnAddMenu);
		btnAddMenu.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				ArrayList<MenuList> myArray=MyHardCode.addMenuList();
				for (int i = 0; i < myArray.size(); i++) {
					DataBaseHelper db = new DataBaseHelper(getApplicationContext());
					db.getWritableDatabase();
					MenuList pMenu = new MenuList();
					pMenu.nameMenu =myArray.get(i).nameMenu;
					pMenu.price=myArray.get(i).price;
					pMenu.linkImg=myArray.get(i).linkImg;
					pMenu.point=myArray.get(i).point;
					pMenu.type=myArray.get(i).type;
					db.addMenu(pMenu);
					
				}
				Toast.makeText(getApplicationContext(), " Added all menu successfully.",
						Toast.LENGTH_SHORT).show();
				finish();
			}
		});
	}

}
